﻿using Microsoft.AspNetCore.Mvc;
using System.Collections;
using Water_and_electricity_metering_management_system.Models.Entitys;

namespace Water_and_electricity_metering_management_system.Controllers
{
    public class ElectricityUseLogController : Controller
    {

        WemmsDbContext dbContext = new WemmsDbContext();

        public IActionResult Index()
        {
            return View();
        }

        [HttpGet]
        public IActionResult getAll()
        {
            var list = dbContext.ElectricityUseLogs.Select(e => e).ToList();
            return Json(list);
        }

        // 条件查询 by datetime
        [HttpGet]
        public IActionResult getByDatetime(string startTime, string endTime)
        {
            DateTime start = System.Convert.ToDateTime(startTime);
            DateTime end = System.Convert.ToDateTime(endTime);
            var list = dbContext.ElectricityUseLogs.Select(e => e).Where(e => e.LogTime >= start && e.LogTime <= end).ToList();
            return Json(list);
        }




    }
}
